home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh -e
-
- . /usr/share/debconf/confmodule
-
- RULES_PATH="/etc/ufw"
- USER_PATH="/lib/ufw"
- TEMPLATE_PATH="/usr/share/ufw"
-
- enable_ufw() {
- ans=""
- if [ "$1" = "true" ]; then
- ans="yes"
- elif [ "$1" = "false" ]; then
- ans="no"
- else
- return 1
- fi
-
- sed -i "s/^ENABLED=.*/ENABLED=$ans/" /etc/ufw/ufw.conf
- }
-
- allow_port() {
- ufw allow "$@" >/dev/null || true
- }
-
- allow_service() {
- service=`echo "$@" | sed 's/#/ /g'`
- if [ "$service" = "CUPS" ]; then
- allow_port 631
- elif [ "$service" = "DNS" ]; then
- allow_port 53
- elif [ "$service" = "IMAPS" ]; then
- allow_port 993/tcp
- elif [ "$service" = "POP3S" ]; then
- allow_port 995/tcp
- elif [ "$service" = "SSH" ]; then
- allow_port 22/tcp
- elif [ "$service" = "CIFS (Samba)" ]; then
- allow_port 137/udp
- allow_port 138/udp
- allow_port 139/tcp
- allow_port 445/tcp
- elif [ "$service" = "SMTP" ]; then
- allow_port 25/tcp
- elif [ "$service" = "HTTP" ]; then
- allow_port 80/tcp
- elif [ "$service" = "HTTPS" ]; then
- allow_port 443/tcp
- fi
- }
-
- case "$1" in
- configure)
- # these files are required, but don't want to change them if
- # the user modified them
- for f in before.rules before6.rules after.rules after6.rules
- do
- ucf --debconf-ok $TEMPLATE_PATH/$f $RULES_PATH/$f
- chmod 640 $RULES_PATH/$f
- done
-
- for f in user.rules user6.rules
- do
- if [ ! -e "$USER_PATH/$f" ]; then
- # if no config, copy the template
- cp $TEMPLATE_PATH/$f $USER_PATH/$f
- chmod 640 $USER_PATH/$f
- fi
- done
-
- # https://bugs.launchpad.net/ufw/+bug/393187
- if dpkg --compare-versions "$2" lt 0.27.1-2 ; then
- for f in before.rules before6.rules after.rules after6.rules
- do
- test -f $RULES_PATH/$f && chmod o-rwx $RULES_PATH/$f
- done
- for f in user.rules user6.rules
- do
- test -f $USER_PATH/$f && chmod o-rwx $USER_PATH/$f
- done
- fi
-
- if [ ! -e "/etc/ufw/ufw.conf" ]; then
- cp $TEMPLATE_PATH/ufw.conf /etc/ufw
- fi
-
- if [ ! -z "$2" ] && dpkg --compare-versions "$2" lt "0.24.1" ; then
- # remove these symlinks for existing installations
- rm -f /etc/rc0.d/K39ufw
- rm -f /etc/rc6.d/K39ufw
- fi
-
- # configure ufw with debconf values
- db_get ufw/enable
- enabled="$RET"
-
- db_fget ufw/existing_configuration seen
- seen_warning="$RET"
- if [ "$enabled" = "true" ] && [ "$seen_warning" = "false" ] ; then
- db_get ufw/allow_known_ports
- CHOICES="$RET"
- for service in `echo "$CHOICES" | sed 's/, /\n/g' | sed 's/ /#/g'`; do
- allow_service "$service"
- done
-
- db_get ufw/allow_custom_ports
- PORTS="$RET"
- for port in $PORTS ; do
- allow_port "$port"
- done
-
- db_fset ufw/existing_configuration seen true
- fi
-
- # need to do this after all 'allow_service' calls, otherwise ufw may
- # try to use iptables, which breaks the installer
- enable_ufw "$enabled"
- ;;
- triggered)
- ufw app update all || echo "Processing ufw triggers failed. Ignoring."
- exit 0
- ;;
- abort-upgrade|abort-remove|abort-deconfigure)
- ;;
- *)
- echo "postinst called with unknown argument '$1'" >&2
- exit 1
- ;;
- esac
-
- # Automatically added by dh_installinit
- update-rc.d -f ufw remove >/dev/null || exit $?
- # End automatically added section
- # Automatically added by dh_pycentral
- rm -f /var/lib/pycentral/ufw.pkgremove
- if which pycentral >/dev/null 2>&1; then
- pycentral pkginstall ufw
- if grep -qs '^ufw$' /var/lib/pycentral/delayed-pkgs; then
- sed -i '/^ufw$/d' /var/lib/pycentral/delayed-pkgs
- fi
- fi
- # End automatically added section
-
-